﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace dotnet_ef_admin.Src.Models;

[Table("user")]
public class User {
    [Key] public int Id { get; set; }

    public string? Username { get; set; }

    public string? Nickname { get; set; }

    public int Gender { get; set; } = 1;

    public string? Password { get; set; }

    [Column("dept_id")] public int? DeptId { get; set; }

    public string? Avatar { get; set; }

    public string? Mobile { get; set; }

    public int Status { get; set; } = 1;

    public string? Email { get; set; }

    public int? Deleted { get; set; } = 0;

    [Column("create_time")] public DateTime? CreateTime { get; set; } = DateTime.Now;

    [Column("update_time")] public DateTime? UpdateTime { get; set; }

    public ICollection<UsersOnRoles> Roles { get; set; } = [];

    public void UpdateStatus(int newStatus) {
        (Status, UpdateTime) = (newStatus, DateTime.Now);
    }
}